<template>
  <div class="common-body-wrapper">
    <search-header
      single-width="130"
      :searchList="searchList"
      @changeHeight="toRetTable"
      @confirmSearch="toSearch"
    ></search-header>

    <multi-fun-table
      :sortColumn="notFormatColumn"
      :orderType="sortType"
      :fixed-cols="fixedCols"
      :is-reset-table="isResetTable"
      :theads-info="theadsInfo"
      :tbodys-info="tbodysInfo"
      @handleMultiCheck="handleMultiCheck"
      @handleSortColumn="handleSortColumn"
      @searchFn="getList"
      @getNextPage="getNextPage"
    >
      <!--按钮-->
      <div class="operate-btn-group" slot="operateBtnGroup">
        <a
          class="ake_btn ake_btn_text"
          v-if="isPermmited('PLATFORM:USER:SAVE')"
          @click.prevent="toOpenAddUserDialog()"
        >新增</a>
        <a
          class="ake_btn ake_btn_text"
          v-if="isPermmited('PLATFORM:USER:DEL')"
          @click.prevent="toOpenUserDelete(null)"
        >批量删除</a>
      </div>

      <!--普通列-->
      <template slot="tdCell" slot-scope="props">
        <el-table-column
          :fixed="props.fixed"
          :label="props.label"
          :min-width="props.minWidth"
          :width="props.width"
          :prop="props.prop"
          :sortable="props.sortable"
        >
          <template slot-scope="scope">
            <span v-if="'reno' == props.prop">{{ scope.$index + 1 }}</span>
            <span v-else-if="'type' == props.prop">{{scope.row[props.prop]|formatType}}</span>
            <span v-else>{{ scope.row[props.prop] }}</span>
          </template>
        </el-table-column>
      </template>

      <!--操作列内的按钮-->

      <template slot="operateCell" slot-scope="props">
        <el-table-column
          :fixed="props.fixed"
          :label="props.label"
          width="190"
          class-name="operateCell"
        >
          <template slot-scope="scope">
            <el-button
              title="设置角色"
              size="small"
              type="primary"
              icon="icon-role"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:USER:SETROLE')"
              @click="toOpenRoleSetting(scope.row,'setRoleModal')"
              plain
            ></el-button>
            <el-button
              title="设置车场分组"
              :disabled="scope.row.type!='OPERATOR_GENERAL'"
              size="small"
              type="primary"
              icon="icon-group"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:USER:SETPARKGROUP')"
              @click="toOpenParkGroupSetting(scope.row,'setParkGroupModal')"
              plain
            ></el-button>
            <el-button
              title="重置密码"
              size="small"
              type="primary"
              icon="icon-password"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:USER:RESETPWD')"
              @click="toOpenPwdEdit(scope.row,'pwdFormModal')"
              plain
            ></el-button>
            <el-button
              title="修改用户"
              size="small"
              type="primary"
              icon="icon-edit"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:USER:UPDATE')"
              @click="toOpenUserEdit(scope.row,'userEditFormModal')"
              plain
            ></el-button>
            <el-button
              title="删除"
              size="small"
              type="danger"
              icon="icon-delete"
              class="ake-icon-font"
              v-if="isPermmited('PLATFORM:USER:DEL')"
              @click="toOpenUserDelete(scope.row)"
              plain
            ></el-button>
          </template>
        </el-table-column>
      </template>
    </multi-fun-table>

    <table-pagination :size="total" :cur-page="pageNumber" @backData="getPagination"></table-pagination>

    <!--modal-->
    <!--至少选择一项  modal-->
    <basic-modal ref="voidTipModal" bodyTxt="请至少选择一项">
      <h3 slot="title">温馨提示</h3>
      <div class="modal-footer" slot="modal-footer">
        <button class="ake_btn ake_btn_text modal-close" @click="closed('voidTipModal')">关闭</button>
      </div>
    </basic-modal>

    <!--修改用户-->
    <basic-modal ref="userEditFormModal" width="600" customeClass="user-row-modal" static="true">
      <h3 slot="title">修改用户【{{userEditForm.loginId}}】</h3>
      <div class="modal-body" slot="modal-body">
        <el-form
          ref="userEditForm"
          :model="userEditForm"
          :rules="rules"
          label-position="left"
          label-width="80px"
        >
          <el-form-item label="登录账号">
            <el-input class="first-item" v-model="userEditForm.loginId" :disabled="true"></el-input>
          </el-form-item>
          <el-form-item label="用户昵称" prop="nickName">
            <el-input class="first-item" v-model="userEditForm.nickName"></el-input>
          </el-form-item>
          <!-- <el-form-item label="手机号码" prop="mobile">
            <el-input class="first-item" v-model="userEditForm.mobile"></el-input>
          </el-form-item>
          <el-form-item label="电子邮箱" prop="email">
            <el-input class="first-item" v-model="userEditForm.email"></el-input>
          </el-form-item>
          <el-form-item label="地址" prop="address">
            <el-input type="textarea" class="first-item" v-model="userEditForm.address"></el-input>
          </el-form-item>-->
        </el-form>
      </div>
      <div class="modal-footer" slot="modal-footer">
        <button
          class="ake_btn ake_btn_text ake_btn_confirm"
          @click.stop="saveUserForm('userEditForm','userEditFormModal')"
        >确认</button>
        <button class="ake_btn ake_btn_text modal-close" @click="closed('userEditFormModal')">取消</button>
      </div>
    </basic-modal>

    <!--重置密码-->
    <basic-modal ref="pwdFormModal" width="600" customeClass="user-row-modal" static="true">
      <h3 slot="title">修改密码【{{pwdForm.loginId}}】</h3>
      <div class="modal-body" slot="modal-body">
        <el-form
          ref="pwdForm"
          :model="pwdForm"
          :rules="pwdRules"
          label-position="left"
          label-width="80px"
        >
          <el-form-item label="用户密码" prop="password">
            <el-input
              class="first-item"
              v-model="pwdForm.password"
              type="password"
              auto-complete="off"
            ></el-input>
          </el-form-item>
          <el-form-item label="确认密码" prop="passWordAgain">
            <el-input
              class="first-item"
              v-model="pwdForm.passWordAgain"
              type="password"
              auto-complete="off"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="modal-footer" slot="modal-footer">
        <button
          class="ake_btn ake_btn_text ake_btn_confirm"
          @click.stop="resetPwd('pwdForm','pwdFormModal')"
        >确认</button>
        <button class="ake_btn ake_btn_text modal-close" @click="closed('pwdFormModal')">取消</button>
      </div>
    </basic-modal>

    <!--设置角色-->
    <basic-modal ref="setRoleModal" width="650" customeClass="user-transfer-modal" static="true">
      <h3 slot="title">设置角色【{{roleForm.loginId}}】</h3>
      <div class="modal-body" slot="modal-body">
        <el-transfer
          v-model="rightRoleArr"
          :props="{
        key: 'id',
        label: 'name'
      }"
          :titles="['全部角色','已设置角色']"
          :data="leftRoleArr"
        ></el-transfer>
      </div>
      <div class="modal-footer" slot="modal-footer">
        <button
          type="button"
          class="ake_btn ake_btn_text ake_btn_confirm"
          @click="setRoleForUser('setRoleModal')"
        >确认</button>
        <button class="ake_btn ake_btn_text modal-close" @click="closed('setRoleModal')">取消</button>
      </div>
    </basic-modal>

    <!--设置停车场-->
    <basic-modal
      ref="setParkGroupModal"
      width="650"
      customeClass="user-transfer-modal"
      static="true"
    >
      <h3 slot="title">设置停车场分组【{{parkGroupForm.loginId}}】</h3>
      <div class="modal-body" slot="modal-body">
        <el-transfer
          v-model="rightParkArr"
          :props="{
        key: 'id',
        label: 'name'
      }"
          :titles="['全部停车场分组','已设置停车场分组']"
          :data="leftParkArr"
        ></el-transfer>
      </div>
      <div class="modal-footer" slot="modal-footer">
        <button
          type="button"
          class="ake_btn ake_btn_text ake_btn_confirm"
          @click="setParkGroupForUser('setParkGroupModal')"
        >确认</button>
        <button class="ake_btn ake_btn_text modal-close" @click="closed('setParkGroupModal')">取消</button>
      </div>
    </basic-modal>

    <!-- 新增用户new -->
    <el-dialog
      title="新增用户"
      :visible.sync="dialogVisibleForUser"
      width="720px"
      class="zb-dialog add-new-dialog"
    >
      <div class="parkinglot-showInfo-content main-content-box">
        <div class="top-tab-box">
          <div class="tab-item" :class="{'active':tabIndex==1}" @click="tabIndex=1">
            <span>1</span>
            <span>创建用户</span>
          </div>
          <div class="tab-item" :class="{'active':tabIndex==2}" @click="tabIndex=2">
            <span>2</span>
            <span>设置角色</span>
          </div>
          <div class="tab-item" :class="{'active':tabIndex==3}" @click="tabIndex=3">
            <span>3</span>
            <span>绑定分组</span>
          </div>
        </div>
        <div class="add-user-box" v-show="tabIndex==1">
          <el-form
            ref="userForm"
            :model="userForm"
            :rules="rules"
            label-position="left"
            label-width="80px"
            size="medium "
          >
            <el-form-item label="登录账号" prop="loginId">
              <el-input v-model="userForm.loginId"></el-input>
            </el-form-item>
            <el-form-item label="登录密码" prop="passWord">
              <el-input v-model="userForm.passWord" type="password" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="确认密码" prop="passWordAgain">
              <el-input v-model="userForm.passWordAgain" type="password" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="用户昵称" prop="nickName">
              <el-input v-model="userForm.nickName"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="setup-role-box" v-show="tabIndex==2">
          <el-checkbox-group v-model="chooseRoleList">
            <el-checkbox v-for="item in allRoleList" :label="item.id">{{item.name}}</el-checkbox>
          </el-checkbox-group>
          <div class="add-btn-box" @click="toOpenAddRoleDialog()">
            <img src="../../assets/img/ic_subscribe_add@2x.svg" alt />
            <span>新增角色</span>
          </div>
        </div>
        <div class="bind-group-box" v-show="tabIndex==3">
          <el-checkbox-group v-model="chooseGroupList">
            <el-checkbox v-for="item in allGroupList" :label="item.id">{{item.name}}</el-checkbox>
          </el-checkbox-group>
          <div class="add-btn-box" @click="toOpenAddGroupDialog()">
            <img src="../../assets/img/ic_subscribe_add@2x.svg" alt />
            <span>新增分组</span>
          </div>
        </div>
      </div>
      <span slot="footer">
        <el-button size="medium" plain @click="dialogVisibleForUser = false" v-if="tabIndex==1">取 消</el-button>
        <el-button size="medium" plain @click="tabIndex--" v-else-if="tabIndex==2 || tabIndex==3">
          <i class="el-icon-arrow-left"></i>上一步
        </el-button>
        <el-button
          type="primary"
          size="medium"
          @click="saveUserForm('userForm',null)"
          v-if="tabIndex==3"
        >完成</el-button>
        <el-button type="primary" size="medium" @click="tabIndex++" v-else>
          下一步
          <i class="el-icon-arrow-right el-icon--right"></i>
        </el-button>
      </span>
    </el-dialog>

    <!-- 新增角色new -->
    <el-dialog
      title="新增角色"
      :visible.sync="dialogVisibleForRole"
      width="720px"
      class="zb-dialog add-new-dialog"
    >
      <div class="parkinglot-showInfo-content main-content-box">
        <div class="top-tab-box">
          <div class="tab-item" :class="{'active':tabIndexForRole==1}" @click="tabIndexForRole=1">
            <span>1</span>
            <span>创建角色</span>
          </div>
          <div class="tab-item" :class="{'active':tabIndexForRole==2}" @click="tabIndexForRole=2">
            <span>2</span>
            <span>设置权限</span>
          </div>
        </div>
        <div class="add-role-box" v-show="tabIndexForRole==1">
          <el-form
            ref="addRoleForm"
            :model="addRoleForm"
            :rules="roleRules"
            label-position="left"
            label-width="80px"
          >
            <el-form-item label="角色名称" prop="name">
              <el-input class="first-item" v-model="addRoleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="描述" prop="remark">
              <el-input type="textarea" class="first-item" v-model="addRoleForm.remark" rows="3"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="setup-role-tree-box" v-show="tabIndexForRole==2">
          <div class="addNewRole-allcheck-box">
            <el-checkbox v-model="isAllCheck" @change="checkAllOrNo">全选/反选</el-checkbox>
            <span>选中{{checkedSum}}项</span>
          </div>
          <ul id="privilegeTree" name="privilegeTree" class="ztree"></ul>
        </div>
      </div>
      <span slot="footer">
        <el-button
          size="medium"
          plain
          @click="dialogVisibleForRole = false"
          v-if="tabIndexForRole==1"
        >取 消</el-button>
        <el-button size="medium" plain @click="tabIndexForRole--" v-else-if="tabIndexForRole==2">
          <i class="el-icon-arrow-left"></i>上一步
        </el-button>
        <el-button
          type="primary"
          size="medium"
          @click="tabIndexForRole++"
          v-if="tabIndexForRole==1"
        >
          下一步
          <i class="el-icon-arrow-right el-icon--right"></i>
        </el-button>
        <el-button
          type="primary"
          size="medium"
          @click="saveAddRoleModal('addRoleForm')"
          v-else-if="tabIndexForRole==2"
        >完成</el-button>
      </span>
    </el-dialog>

    <!-- 新增分组new -->
    <el-dialog
      title="新增分组"
      :visible.sync="dialogVisibleForGroup"
      width="720px"
      class="zb-dialog add-new-dialog"
    >
      <div class="parkinglot-showInfo-content main-content-box">
        <div class="top-tab-box">
          <div class="tab-item" :class="{'active':tabIndexForGroup==1}" @click="tabIndexForGroup=1">
            <span>1</span>
            <span>创建分组</span>
          </div>
          <div class="tab-item" :class="{'active':tabIndexForGroup==2}" @click="tabIndexForGroup=2">
            <span>2</span>
            <span>绑定停车场</span>
          </div>
        </div>
        <div class="add-group-box" v-show="tabIndexForGroup==1">
          <el-form
            ref="addGroupForm"
            :model="addGroupForm"
            :rules="groupRules"
            label-position="left"
            label-width="80px"
          >
            <el-form-item label="分组名称" prop="name">
              <el-input class="first-item" v-model="addGroupForm.name"></el-input>
            </el-form-item>
            <el-form-item label="描述" prop="remark">
              <el-input type="textarea" class="first-item" v-model="addGroupForm.remark" rows="3"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="choose-parking-box" v-show="tabIndexForGroup==2">
          <ul id="parkTree" name="parkTree" class="ztree"></ul>
        </div>
      </div>
      <span slot="footer">
        <el-button
          size="medium"
          plain
          @click="dialogVisibleForGroup = false"
          v-if="tabIndexForGroup==1"
        >取 消</el-button>
        <el-button size="medium" plain @click="tabIndexForGroup--" v-else-if="tabIndexForGroup==2">
          <i class="el-icon-arrow-left"></i>上一步
        </el-button>
        <el-button
          type="primary"
          size="medium"
          @click="tabIndexForGroup++"
          v-if="tabIndexForGroup==1"
        >
          下一步
          <i class="el-icon-arrow-right el-icon--right"></i>
        </el-button>
        <el-button
          type="primary"
          size="medium"
          @click="saveAddGroupModal('addGroupForm')"
          v-else-if="tabIndexForGroup==2"
        >完成</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import common from "@mixins/common.js";
import stardardList from "@mixins/tables/stardardList.js";

//modal
import invokeModal from "@mixins/modal/invokeModal.js";

// 引进vue的js
import User from "./js/User.js";

export default {
  name: "authzUser",
  mixins: [common, stardardList, invokeModal, User],
  data() {
    return {
      total: 0,
      fixedCols: 0,
      searchList: [
        {
          index: 0,
          isShow: false,
          type: "text",
          name: "loginId",
          text: "登录账号",
          value: ""
        },
        {
          index: 1,
          isShow: false,
          type: "text",
          name: "mobile",
          text: "用户电话",
          value: ""
        },
        {
          index: 2,
          isShow: false,
          type: "text",
          name: "email",
          text: "用户邮箱",
          value: ""
        }
      ],
      theadsInfo: [
        { index: 0, isShow: false, prop: "reno", text: "序号", width: 68 },
        // { index: 1, isShow: false, prop: 'type', text: '类型', minWidth: 50,initHidden: true },
        {
          index: 1,
          isShow: false,
          prop: "loginId",
          text: "登录账号",
          minWidth: 50
        },
        {
          index: 2,
          isShow: false,
          prop: "nickName",
          text: "用户昵称",
          minWidth: 50
        },
        {
          index: 3,
          isShow: false,
          prop: "mobile",
          text: "手机号码",
          minWidth: 60
        }
      ],
      tbodysInfo: []
    };
  },
  filters: {
    formatType: function(type) {
      return type == "OPERATOR_GENERAL"
        ? "管理员"
        : type == "OPERATOR"
        ? "运营商"
        : "";
    }
  }
};
</script>

<style scoped lang="less">
.parkinglot-showInfo-content {
  position: relative;
}
.addNewRole-allcheck-box {
  position: absolute;
  top: 385px;
  width: 96%;
  display: flex;
  justify-content: space-between;
  background: #fff;
}
.top-tab-box {
  height: 60px;
  display: -ms-flexbox;
  display: flex;
}
.top-tab-box .tab-item {
  height: 60px;
  line-height: 60px;
  -ms-flex: 1;
  flex: 1;
  text-align: center;
  border-bottom: 1px solid #d7dce2;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-align: center;
  align-items: center;
  -ms-flex-pack: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}
.top-tab-box .tab-item.active {
  span:first-child {
    background: #5995d8;
    color: #ffffff;
  }
  span:last-child {
    color: #5995d8;
  }

  &:after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: #5995d8;
  }
}
.top-tab-box .tab-item span:first-child {
  width: 24px;
  height: 24px;
  line-height: 24px;
  background: #d7dce2;
  text-align: center;
  border-radius: 12px;
  color: #ffffff;
}
.top-tab-box .tab-item span:last-child {
  padding-left: 10px;
  font-size: 14px;
  color: #999999;
}
</style>

<style lang="less">
.add-new-dialog {
  .el-dialog {
    .el-dialog__body {
      padding: 0px !important;
    }
  }
}
</style>

<style lang="less" scoped>
.dialog-footer {
  width: 100%;
  text-align: right;
  .footer-tip-box {
    padding-right: 125px;
    .red-tip {
      color: #d0021b;
    }
    .footer-text-tip {
      color: #666666;
    }
  }
}
.add-user-box,
.add-role-box,
.add-group-box {
  padding-top: 30px;
  padding-bottom: 100px;
  width: 55%;
  margin: 0px auto;
}
.setup-role-box,
.bind-group-box {
  padding-bottom: 100px;
}
.setup-role-tree-box,
.choose-parking-box {
  margin-top: 20px;
  height: 300px;
  overflow-y: scroll;
  #privilegeTree {
    width: 50%;
    margin: 0 auto;
  }
  #parkTree {
    width: 50%;
    margin: 0 auto;
  }
}
.setup-role-box,
.bind-group-box {
  height: 420px;
  overflow-y: scroll;
  .add-btn-box {
    margin-top: 20px;
    text-align: center;
    cursor: pointer;
    img {
      width: 16px;
      height: 16px;
      position: relative;
      bottom: 2px;
    }
    span {
      font-size: 14px;
      color: #5995d8;
      padding-left: 5px;
    }
  }
  .el-checkbox-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 30px;
    .el-checkbox {
      margin-left: 30px;
      width: 250px;
      height: 40px;
      line-height: 40px;
      padding-left: 30px;
      background: #f6f6f6;
      border: 1px solid #ebebeb;
      border-radius: 4px;
      margin-top: 10px;
      &:last-child {
        margin-left: 5px;
      }
      .el-checkbox__input {
        margin-right: 10px;
      }
    }
  }
}

.user-row-modal {
  .first-item {
    width: 240px;
  }
}

//调整transfer的样式
.user-transfer-modal {
  .modal-body {
    margin: 0 auto;
  }
  .el-checkbox + .el-checkbox {
    margin-left: 0;
  }
  .el-button + .el-button {
    margin-left: 0;
  }
}

.role-select {
  width: 240px;
}
</style>
